const connection = require("../app/database")

class PermissionService {
  async checkMoment(momentId, userId) {
    const statement = "SELECT * FROM moment WHERE id = ? AND user_id = ?;"
    const [res] = await connection.execute(statement, [momentId, userId])
    // console.log(res)
    // @ts-ignore
    return !!res.length
  }

  async checkResouce(resourceName, resourceId, userId) {
    const statement = `SELECT * FROM ${resourceName} WHERE id = ? AND user_id = ?;`
    const [result] = await connection.execute(statement, [resourceId, userId])
    // @ts-ignore
    return !!result.length
  }
}

module.exports = new PermissionService()
